package com.hyq.learn.api.config.datasource;

import com.hyq.learn.api.enumtype.DatasourceType;
import com.zaxxer.hikari.HikariConfig;
import jakarta.validation.constraints.NotNull;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.Map;

/**
 * 多数据源配置文件
 *
 * @author heyuqin
 * @date 2024/5/29 15:20
 */
@Validated
@ConfigurationProperties(prefix = "learn.datasource", ignoreInvalidFields = true)
public class DbProperties {

    private Map<DatasourceType, LearnDs> multiDs = new HashMap<>();

    public void setMultiDs(Map<DatasourceType, LearnDs> multiDs) {
        this.multiDs = multiDs;
    }

    public Map<DatasourceType, LearnDs> getMultiDs() {
        return multiDs;
    }

    public static class LearnDs {
        @NotNull
        private DataSourceProperties datasource;
        @NotNull
        private HikariConfig hikari;

        public DataSourceProperties getDatasource() {
            return datasource;
        }

        public void setDatasource(DataSourceProperties datasource) {
            this.datasource = datasource;
        }

        public HikariConfig getHikari() {
            return hikari;
        }

        public void setHikari(HikariConfig hikari) {
            this.hikari = hikari;
        }
    }

}
